// 路由词典配置   和  路由器配置
import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '../views/Index.vue'

Vue.use(VueRouter)

  const routes = [
  //鄙视题:Vue.js中有几种路由守卫
  //meta:路由的元数据-其中可以指定任意的数据
  { path: '/', component: Index ,meta:{title:"首页-iweb在线课堂"}},
  //对于用户不会立即访问的页面,进行延迟加载,lazy-loaded:访问到这一页的时候再导入vue
  {path: '/address',meta:{title:"地址-iweb在线课堂"},component: () => import('../views/Address.vue')},
  {path: '/cart',meta:{title:"购物车-iweb在线课堂"},component: () => import('../views/Cart.vue')},
  {path: '/course',meta:{title:"课程-iweb在线课堂"},component: () => import('../views/Course.vue')},
  {path: '/course-detail/:cid',meta:{title:"课程详情-iweb在线课堂"},component: () => import('../views/CourseDetail.vue')},
  {path: '/index',meta:{title:"课程列表-iweb在线课堂"},component: () => import('../views/Index.vue')},
  {path: '/login',meta:{title:"登录-iweb在线课堂"},component: () => import('../views/Login.vue')},
  {path: '/order',meta:{title:"订单-iweb在线课堂"},component: () => import('../views/Order.vue')},
  {path: '/register',meta:{title:"注册-iweb在线课堂"},component: () => import('../views/Register.vue')},
  {path: '/teachers',meta:{title:"讲师列表-iweb在线课堂"},component: () => import('../views/Teachers.vue')},
  {path: '/*',meta:{title:"404-iweb在线课堂"},component: () => import('../views/PageNotFound.vue')},
  

];


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

//全局前置路由守卫,在客户端访问任意一个页面的时候,
router.beforeEach((to, from, next) => {
	if(to.meta && to.meta.title){
	   document.title=to.meta.title;
	}
	//守卫放行
	next()
})


export default router
